package com.lastproject.web.bean;

import java.util.Calendar;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import com.lastproject.dto.CategoryDTO;
import com.lastproject.dto.SubcategoryDTO;
import com.lastproject.dto.SurveyDTO;
import com.lastproject.dto.TopicDTO;
import com.lastproject.ejb.dao.CategoryDAORemote;
import com.lastproject.ejb.dao.SubcategoryDAORemote;
import com.lastproject.ejb.dao.SurveyDAORemote;
import com.lastproject.ejb.dao.TopicDAORemote;

///**
// * Session Bean implementation class AnswerStatsBean
// */
@ManagedBean(name = "surveyListForUserBean")
@RequestScoped
public class SurveyListForUserBean {
	
	private String status;
	
//	@ManagedProperty(value = "#{userDTO}")
//	private UserDTO userDTO;
//	@EJB
//	UserDAORemote userDao;
	
	@ManagedProperty(value = "#{surveyDTO}")
	private SurveyDTO surveyDTO;
	@EJB
	SurveyDAORemote surveyDao;
	
	@ManagedProperty(value = "#{topicDTO}")
	private TopicDTO topicDTO;
	@EJB
	TopicDAORemote topicDao;
	
	@ManagedProperty(value = "#{categoryDTO}")
	private CategoryDTO categoryDTO;
	@EJB
	CategoryDAORemote categoryDao;
	
	@ManagedProperty(value = "#{subcategoryDTO}")
	private SubcategoryDTO subcategoryDTO;
	@EJB
	SubcategoryDAORemote subcategoryDao;
	
	
	public SurveyListForUserBean() {
		
	}
	
	public SurveyListForUserBean(SurveyDTO surveyDTO) {
		this.surveyDTO = surveyDTO;
	}
		
//	public UserDTO getUserDTO() {
//		return userDTO;
//	}
//	public void setUserDTO(UserDTO userDTO) {
//		this.userDTO = userDTO;
//	}
	
	public SurveyDTO getSurveyDTO() {
		return surveyDTO;
	}
	public void setSurveyDTO(SurveyDTO surveyDTO) {
		this.surveyDTO = surveyDTO;
	}
	public TopicDTO getTopicDTO() {
		return topicDTO;
	}
	public void setTopicDTO(TopicDTO topicDTO) {
		this.topicDTO = topicDTO;
	}
	public CategoryDTO getCategoryDTO() {
		return categoryDTO;
	}
	public void setCategoryDTO(CategoryDTO categoryDTO) {
		this.categoryDTO = categoryDTO;
	}
	public SubcategoryDTO getSubcategoryDTO() {
		return subcategoryDTO;
	}
	public void setSubcategoryDTO(SubcategoryDTO subcategoryDTO) {
		this.subcategoryDTO = subcategoryDTO;
	}

	public String getStatus() {
		Calendar calStart = Calendar.getInstance();
		Calendar calEnd = Calendar.getInstance();
		
		Calendar calToday = Calendar.getInstance();
		try{
		calStart.setTime(this.getSurveyDTO().getStartDate());
		calEnd.setTime(this.getSurveyDTO().getEndDate());
		
		if (calStart.after(calToday)) {
			status = "not yet available";
		} else if (calEnd.after(calToday) || calEnd.equals(calToday)) {
			status = "ongoing";
		} else if (calEnd.before(calToday)) {
			status = "completed";
		}
		} catch(NullPointerException e) {
			status = "no date set";
		}
			
		
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
//		this.getSurveyDTO()
	}
	
	

}
